<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<include file="Public/head" />
<link href="__STATIC__/css/user.css" type="text/css" rel="stylesheet" />
</head>

<body>
<include file="Public/top" />

<div class="page_minheight">
<div class="login_tit">
  <div class="return"><a href="{:U('User/index')}"><i class="icon-fanhui"></i></a></div>
  <span>邮箱验证</span>
</div><!--login_tit-->
<div class="page_in margin">
  <form action="" method="post" onSubmit="return check_form();">
    <div class="ginput_div ginput_div_icon"><i class="icon-shouji1"></i><input class="ginput" type="text" name="old_email" id="old_email" value="{$user_info['email']}" readonly /></div>
    <div class="ginput_div ginput_div_icon"><i class="icon-shouji1"></i><input class="ginput" type="text" name="email" id="email" placeholder="{$Think.lang.new_mailbox}" /></div>
    <div class="ginput_div ginput_div_icon">
      <div class="fl"><i class="icon-yanzhengma2"></i><input class="ginput" name="code" id="new_code" type="text" placeholder="验证码" /></div>
      <div class="fr"><button type="button" class="reg_send" id="btnemailAuthCode2" onClick="sendCode(this,'email')">获取验证码</button></div>
      <div class="clear"></div>
    </div>
    <div class="ginput_div"><button type="submit" class="login_sub">提交</button></div>
  </form>
</div><!--page_in-->
</div><!--page_minheight-->

<script>
    // 表单提交验证
    function check_form() {
        var old_email = $('#old_email').val();
        var new_email = $('#email').val();
        //原邮箱不为空的情况下 验证格式
        //240874144@qq.com

        if (old_email != '' && typeof(old_email) != 'undefined') {
            if (!checkEmail(old_email)) {
                layer.alert('原邮箱格式错误', {icon: 2});//alert('原邮箱格式错误');
                return false;
            }
        }

        if (!checkEmail(new_email)) {
            layer.alert('新邮箱格式错误', {icon: 2});//alert('新邮箱格式错误');
            return false;
        }

        if ($.trim($('#new_code').val()) == '') {
            layer.alert('{$Think.lang.code_not_empty} ', {icon: 2});//alert('验证码不能为空');
            return false;
        }
        return true;
    }

    function sendCode(obj, input_id) {
        var id = $(obj).attr('id');
        var input = $('#' + input_id).val();
        var old_email = $('#old_email').val();
        //原邮箱不为空的情况下 验证格式
        if (old_email != '' && typeof(old_email) != 'undefined') {
            if (!checkEmail(old_email)) {
                layer.alert('旧邮箱格式错误 ', {icon: 2});//alert('原邮箱格式错误');
                return false;
            }
        }



        if (!checkEmail(input)) {
            layer.alert('新邮箱格式错误 ', {icon: 2});//alert('邮箱格式错误');
            return false;
        }
        if (input_id == 'old_email')
            var url = "/index.php?m=Mobile&c=User&a=send_validate_code&step=1&type=email&send=" + input;
        if (input_id == 'new_email')
            var url = "/index.php?m=Mobile&c=User&a=send_validate_code&step=2&type=email&send=" + input;
        //发送验证码
        $.ajax({
            type: "GET",
            url: url,
            dataType: 'json',
            error: function (request) {
                layer.alert('{$Think.lang.please_contact_admin} ', {icon: 2});//alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function (res) {
                if (res.status == 1) {
                    jsInnerTimeout(id);
                } else {
                    layer.alert(res.msg, {icon: 2});//alert('发送失败');
                }
            }
        });
    }

    //倒计时函数
    function jsInnerTimeout(id) {
        var codeObj = $("#" + id);
        var intAs = parseInt(codeObj.attr("IntervalTime"));

        intAs--;
        codeObj.attr("disabled", "disabled");
        if (intAs <= -1) {
            codeObj.removeAttr("disabled");
            codeObj.attr("IntervalTime", 120);
            codeObj.val("{$Think.lang.get_code} ");
            return true;
        }
        codeObj.val(intAs + 's{$Think.lang.again_after_obtaining} ');
        codeObj.attr("IntervalTime", intAs);
        setTimeout("jsInnerTimeout('" + id + "')", 1000);
    }
    ;

</script>

<include file="Public/footer" />
<script src="__STATIC__/js/global_after.js" type="text/javascript"></script>
</body>
</html>